<template>
  <div class="supply-chain-layout">
    <!-- 菜单切换按钮 -->
    <div class="menu-toggle" @click="toggleMenu">
      <svg v-if="isMenuCollapsed" class="toggle-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
        <path d="M4 6h16M4 12h16M4 18h16" stroke-width="2" stroke-linecap="round"/>
      </svg>
      <svg v-else class="toggle-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor">
        <path d="M18 6L6 18M6 6l12 12" stroke-width="2" stroke-linecap="round"/>
      </svg>
    </div>

    <!-- 左侧导航栏 -->
    <div class="sidebar" :class="{ collapsed: isMenuCollapsed }">
      <div class="sidebar-title">
        <span v-if="!isMenuCollapsed">导航栏</span>
        <span v-else class="sidebar-icon">☰</span>
      </div>
      <div class="nav-menu">
        <div 
          v-for="item in navItems" 
          :key="item.path"
          class="nav-item"
          :class="{ active: currentPath === item.path }"
          @click="navigate(item.path)"
          :title="isMenuCollapsed ? item.name : ''"
        >
          <span v-if="!isMenuCollapsed">{{ item.name }}</span>
          <span v-else class="nav-icon">{{ getNavIcon(item.name) }}</span>
        </div>
      </div>
    </div>

    <!-- 主内容区 -->
    <div class="main-content">
      <!-- 顶部标题和筛选器 -->
      <div class="top-section">
        <div class="page-title">供应链基础数据可视化产品</div>
        <div class="filters">
          <select v-model="filters.supplierType" class="filter-select">
            <option value="所有">供应商类型</option>
            <option value="所有">所有</option>
            <option value="类型A">类型A</option>
            <option value="类型B">类型B</option>
          </select>
          <select v-model="filters.supplierName" class="filter-select">
            <option value="所有">供应商名称</option>
            <option value="所有">所有</option>
          </select>
          <select v-model="filters.customerType" class="filter-select">
            <option value="所有">客户类型</option>
            <option value="所有">所有</option>
            <option value="Hospital">Hospital</option>
            <option value="Pharmacy">Pharmacy</option>
            <option value="Clinic">Clinic</option>
          </select>
          <select v-model="filters.customerName" class="filter-select">
            <option value="Customer_10">客户名称</option>
            <option value="Customer_10">Customer_10</option>
            <option value="所有">所有</option>
          </select>
          <select v-model="filters.productCategory" class="filter-select">
            <option value="所有">产品类别</option>
            <option value="所有">所有</option>
            <option value="Antibiotics">Antibiotics</option>
            <option value="Antiviral">Antiviral</option>
            <option value="Painkillers">Painkillers</option>
          </select>
          <select v-model="filters.productName" class="filter-select">
            <option value="所有">产品名称</option>
            <option value="所有">所有</option>
          </select>
          <select v-model="filters.yearMonth" class="filter-select">
            <option value="所有">年、月份</option>
            <option value="所有">所有</option>
            <option value="2024">2024</option>
            <option value="2023">2023</option>
          </select>
        </div>
      </div>

      <!-- 页面内容 -->
      <div class="content-area">
        <slot />
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

const currentPath = computed(() => route.path)
const isMenuCollapsed = ref(false)

const navItems = [
  { name: 'Dashboard', path: '/dashboard' },
  { name: '绩效分析', path: '/performance' },
  { name: '采购分析', path: '/procurement' },
  { name: '库存管理', path: '/inventory' },
  { name: '运输配送', path: '/logistics' },
  { name: '订单分析', path: '/orders' },
  { name: '成本分析', path: '/cost' },
  { name: '监控预警', path: '/monitoring' }
]

const filters = ref({
  supplierType: '所有',
  supplierName: '所有',
  customerType: '所有',
  customerName: 'Customer_10',
  productCategory: '所有',
  productName: '所有',
  yearMonth: '所有'
})

const toggleMenu = () => {
  isMenuCollapsed.value = !isMenuCollapsed.value
}

const navigate = (path) => {
  router.push(path)
}

const getNavIcon = (name) => {
  const iconMap = {
    'Dashboard': '📊',
    '绩效分析': '📈',
    '采购分析': '🛒',
    '库存管理': '📦',
    '运输配送': '🚚',
    '订单分析': '📋',
    '成本分析': '💰',
    '监控预警': '⚠️'
  }
  return iconMap[name] || '●'
}

// 暴露筛选器数据供子组件使用
defineExpose({
  filters
})
</script>

<style scoped>
.supply-chain-layout {
  display: flex;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, #0a0e27 0%, #1a1f3a 100%);
  color: #fff;
  position: relative;
}

.menu-toggle {
  position: fixed;
  left: 10px;
  top: 10px;
  z-index: 1000;
  width: 40px;
  height: 40px;
  background: rgba(24, 144, 255, 0.8);
  border: 1px solid rgba(24, 144, 255, 0.5);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s;
}

.menu-toggle:hover {
  background: rgba(24, 144, 255, 1);
  transform: scale(1.1);
}

.toggle-icon {
  width: 20px;
  height: 20px;
  color: #fff;
  stroke: currentColor;
}

.sidebar {
  width: 200px;
  background: rgba(15, 25, 45, 0.8);
  border-right: 1px solid rgba(24, 144, 255, 0.3);
  padding: 20px 0;
  transition: all 0.3s ease;
  overflow: hidden;
}

.sidebar.collapsed {
  width: 60px;
}

.sidebar-title {
  padding: 0 20px 20px;
  font-size: 16px;
  color: #999;
  border-bottom: 1px solid rgba(24, 144, 255, 0.2);
  margin-bottom: 20px;
  white-space: nowrap;
  transition: all 0.3s;
}

.sidebar.collapsed .sidebar-title {
  padding: 0 10px 20px;
  text-align: center;
}

.sidebar-icon {
  font-size: 20px;
  display: inline-block;
}

.nav-menu {
  display: flex;
  flex-direction: column;
}

.nav-item {
  padding: 15px 20px;
  cursor: pointer;
  transition: all 0.3s;
  color: #999;
  border-left: 3px solid transparent;
  white-space: nowrap;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  position: relative;
}

.sidebar.collapsed .nav-item {
  padding: 15px 10px;
  justify-content: center;
}

.nav-item:hover {
  background: rgba(24, 144, 255, 0.1);
  color: #fff;
}

.nav-item.active {
  background: rgba(24, 144, 255, 0.2);
  color: #36cfc9;
  border-left-color: #36cfc9;
}

.nav-icon {
  font-size: 18px;
  display: inline-block;
}

.sidebar.collapsed .nav-item {
  position: relative;
}

.sidebar.collapsed .nav-item::after {
  content: attr(title);
  position: absolute;
  left: 100%;
  margin-left: 10px;
  background: rgba(0, 0, 0, 0.9);
  padding: 8px 12px;
  border-radius: 4px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 1000;
  border: 1px solid rgba(24, 144, 255, 0.5);
}

.sidebar.collapsed .nav-item:hover::after {
  opacity: 1;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: margin-left 0.3s ease;
  margin-left: 0;
}

.sidebar.collapsed ~ .main-content {
  margin-left: 0;
}

.top-section {
  padding: 20px 30px;
  border-bottom: 1px solid rgba(24, 144, 255, 0.2);
}

.page-title {
  font-size: 24px;
  font-weight: bold;
  margin-bottom: 20px;
  text-align: center;
  background: linear-gradient(90deg, #1890ff, #36cfc9);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-select {
  flex: 1;
  min-width: 120px;
  padding: 8px 12px;
  background: rgba(15, 25, 45, 0.6);
  border: 1px solid rgba(24, 144, 255, 0.3);
  border-radius: 4px;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.3s;
}

.filter-select:hover {
  border-color: rgba(24, 144, 255, 0.6);
}

.filter-select:focus {
  outline: none;
  border-color: #1890ff;
}

.filter-select option {
  background: #1a1f3a;
  color: #fff;
}

.content-area {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
}
</style>
